package cn.gok.homework;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Homework {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<Book> bookClass = (Class<Book>) Class.forName("homework.Book");
        Constructor constructor = bookClass.getConstructor(int.class,String.class,float.class);
        Book book = (Book) constructor.newInstance(1,"猪八戒三打唐僧", 466);
        System.out.println(book);
        System.out.println();
        Method method = bookClass.getDeclaredMethod("sell", Float.class, String.class);
        method.setAccessible(true);
        method.invoke(book,190f, "唐三国");
//        System.out.println(bookClass.getDeclaredFields());
//        System.out.println(bookClass.getFields());
    }
}